<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   城市站点模型($$)*/

!defined('Q_PATH') && exit;

class SiteModel extends CommonModel{

	static public function init__(){
		return array(
			'table_name'=>'site',
			'check'=>array(
				'site_sort'=>array(
					array('number',Q::L('序号只能是数字','__COMMON_LANG__@Common')),
				),
				'site_name'=>array(
					array('require',Q::L('站点名字不能为空','__COMMON_LANG__@Common')),
					array('max_length',50,Q::L('站点名字最大长度为50','__COMMON_LANG__@Common')),
					array('siteName',Q::L('站点名字已经存在','__COMMON_LANG__@Common'),'condition'=>'must','extend'=>'callback'),
				),
				'site_domain'=>array(
					array('require',Q::L('站点域名不能为空','__COMMON_LANG__@Common')),
					array('english',Q::L('站点域名只能为英文字符','__COMMON_LANG__@Common')),
					array('max_length',20,Q::L('站点域名最大长度为20','__COMMON_LANG__@Common')),
					array('siteDomain',Q::L('站点域名已经存在','__COMMON_LANG__@Common'),'condition'=>'must','extend'=>'callback'),
				),
				'city_id'=>array(
					array('cityId',Q::L('站点地区已经存在','__COMMON_LANG__@Common'),'condition'=>'must','extend'=>'callback'),
				),
			),
		);
	}

	static function F(){
		$arrArgs=func_get_args();
		return ModelMeta::instance(__CLASS__)->findByArgs($arrArgs);
	}

	static function M(){
		return ModelMeta::instance(__CLASS__);
	}

	public function siteDomain(){
		return self::uniqueField_('site_domain','site_id','id');
	}

	public function siteName(){
		return self::uniqueField_('site_name','site_id','id');
	}

	public function cityId(){
		return self::uniqueField_('city_id','site_id','id');
	}

	static function getSiteName($nId,$sField='site_name'){
		return self::F('site_id=?',$nId)->getColumn($sField);
	}

	protected function beforeSave_(){
		$this->site_domain=strtolower(C::text($this->site_domain));
		$this->site_name=C::text($this->site_name);
		$this->site_seotitle=C::strip($this->site_seotitle);
		$this->site_seokeywords=C::strip($this->site_seokeywords);
		$this->site_seodescription=C::strip($this->site_seodescription);

		if($this->site_template<1){
			$this->site_template=1;
		}
		if($this->site_template>10){
			$this->site_template=10;
		}

		if($this->site_sort<0){
			$this->site_sort=0;
		}
		if($this->site_sort>999){
			$this->site_sort=999;
		}
	}

}
